{# SPDX-License-Identifier: Apache-2.0 -#}

{% extends "admin/base.html" %}

{% block title %}Decode Token{% endblock %}

{% block breadcrumb %}
<li class="breadcrumb-item active">Decode Token</li>
{% endblock %}

{% block content %}
<div class="card">
  <div class="card-header">Decode an API Token</div>
  <div class="card-body">
    <form action="/admin/token/decode" method="POST">
      <input name="csrf_token" type="hidden" value="{{ request.session.get_csrf_token() }}">
      <div class="input-group input-group-lg">
        <input name="token" type="text" class="form-control input-lg" placeholder="pypi-AgE... "{% if query %} value="{{ query }}"{% endif %}>
        <div class="input-group-btn input-group-append">
          <button type="submit" class="btn btn-default"><i class="fa-solid fa-qrcode"></i></button>
        </div>
      </div>
    </form>
  {% if macaroon %}
    <hr/>
    <table class="table table-striped">
      <tbody>
      <tr>
        <td>Location</td>
        <td>{{ macaroon.location }}</td>
      </tr>
      <tr>
        <td>Identifier</td>
        <td>
          {%  if db_record.id %}
          <a href="{{ request.route_path('admin.macaroon.detail', macaroon_id=db_record.id) }}">
            {{ macaroon.identifier.decode() }}
          </a>
          {% else %}
            {{ macaroon.identifier.decode() }} (Not found)
          {% endif %}
        </td>
      </tr>
      <tr>
        <td>Signature</td>
        <td>{{ macaroon.signature }}</td>
      </tr>
      <tr>
        <td>Caveats</td>
        <td>
          {% for caveat in macaroon.caveats %}
            {{ caveat.to_dict()|pprint }}
          {% endfor %}
        </td>
      </tr>
      </tbody>
    </table>
{% endif %}
  </div>
</div>
{% endblock %}
